Author: Vivek Gite Last updated: February 19, 2017 2 comments
I just followed your tutorial and setup KVM with Ubuntu Linux as a new guest virtual machine. However, I am unable to use the command: ‘virsh console vm’. How do I setup and enable console access in order to gain shell access on the newly created Ubuntu Linux 16.04 LTS VM?
Activating the serial console in the Ubuntu Linux 16.04 LTS guest is an excellent way to log in and solve problems.
1.KVM host IP: 192.168.2.15
2.KVM guest OS: Ubuntu Linux 16.04 LTS
3.KVM guest IP: 192.168.2.45
4.KVM guest name: ubuntu-box1
5.KVM guest user name: vivek
6.KVM guest password: hidden-secrete
First, you need to login using ssh or VNC client to your Ubuntu guest.
In this example, I am login using ssh client from my workstation (or type command on KVM host itself) to the Ubuntu Linux VM guest:
$ ssh vivek@192.168.2.45
After log in gain access to the root shell:
$ sudo -s
Type the following command on your KVM host:
$ virsh dumpxml ubuntu-box1 | grep vnc
<graphics type='vnc' port='5901' autoport='yes' listen='127.0.0.1'>
Please note down the port value (i.e. 5901). You need to use an SSH client to setup tunnel and a VNC client to access the remote vnc server. Type the following SSH port forwarding command from your Linux/Unix/MacOS client or desktop system:
$ ssh {user}@{KVM-host-IP-here} -L 5901:127.0.0.1:5901
$ ssh vivek@192.168.2.15 -L 5901:127.0.0.1:5901
Once you have ssh tunnel established, you can point your VNC client at your own IP 127.0.0.1 (localhost) address and port 5901 as follows in VNC client:
Fig.01: Graphical VNC client to connect to Ubuntu Linux 16.04 LTS server console
Log in to your VM:
Finally type the following two commands to enable a serial console in the guest to access a connection using ‘virsh console’ command:
$ sudo systemctl enable serial-getty@ttyS0.service
$ sudo systemctl start serial-getty@ttyS0.service
Sample outputs:
Created symlink from /etc/systemd/system/getty.target.wants/serial-getty@ttyS0.service to /lib/systemd/system/serial-getty@.service.
To see a list of running VM, enter:
$ virsh list
Sample outputs:
Id Name State
----------------------------------------------------
1 freebsd running
2 ubuntu-box1 running
3 ubuntu-box2 running
Type the following command from KVM host to login to the guest named ubuntu-box1
$ virsh console ubuntu-box1
OR
$ virsh console 2
Sample session:
Use Ctrl + ]to exit the console.